<?php

namespace App\Admin\Controllers\Admin;

use App\Models\Admin\Pinion;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Row;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Column;

use App\Http\Controllers\Controller;


class PinionController extends Controller
{
    use HasResourceActions;
    protected $header = '客户留言';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header($this->header)
            ->description('Detail')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('description');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Pinion::class, function (Grid $grid) {

            $grid->model()->with('user')->orderBy('create_at', 'desc');
            $grid->user()->username('用户名');
            $grid->user()->telephone('手机号');
            //$grid->telephone('手机号');
            $grid->content('内容');
            $grid->role_id('角色')->using([
                '1' => '老师',
                '2' => '家长'
            ]);
            $grid->create_at('时间');

            //去除创建按钮
            $grid->disableCreateButton();

            //搜索栏
            $grid->filter(function (Grid\Filter $filter) {
                $filter->disableIdFilter();
                $filter->like('user.telephone');
            });

            //操作栏
            $grid->actions(function (Grid\Displayers\Actions $actions){
                //$actions->disableDelete();
                $actions->disableEdit();
                $actions->disableView();
            });

            /*$grid->tools(function (Grid\Tools $tools){
                $tools->disableFilterButton();
            });*/

        });
    }


    public function detail($id)
    {
        $show = new Show(Pinion::findOrFail($id));

        $show->user()->username('用户名');
        $show->user()->telephone('手机号');
        $show->content('内容');

        $show->panel()->tools(function (Show\Tools $tools){
            $tools->disableEdit();
        });

        return $show;
    }




}
